var datazhu = {};
var databiaoge ={};
	$.ajax({
	    url: url+'user/login',
	    type: 'post',
   		dataType: 'json',
   		data:JSON.stringify({
   			'name':'qdkj-test',
   			'password':123456
   		}),
   		contentType: "application/json;charset=utf-8",
	async : false,//需要改成同步的
	}).done(function(data, status, jqXHR){
		$.ajax({
		    url: url+'system/deviceActivity?days=7', 
		    type: 'get',
		    dataType: 'json',
		    contentType: "application/json;charset=utf-8",
		    async : false,//需要改成同步的
		    success:function(res){
		    	datazhu = JSON.stringify(res, null, 4);
		    	datazhu = JSON.parse(datazhu);
		    }
		})
	});


datazhu = datazhu.content;
var myDate = new Date();
var jintian = myDate.getDate();
var zhuZT = echarts.init(document.getElementById('zhuzt'));
var dataAxis = [(jintian-6).toString()+'日', (jintian-5).toString()+'日', (jintian-4).toString()+'日', (jintian-3).toString()+'日', (jintian-2).toString()+'日', (jintian-1).toString()+'日', (jintian).toString()+'日'];
var yMax = 40;
var zhuoption = {
textStyle: {
	color: '#fff'//柱状图每条数据的字体颜色
},
xAxis: {
	data: dataAxis,
	axisLabel: {
		inside: true,
		textStyle: {
			color: '#fff'//柱状图横坐标字体颜色
		}
	},
	axisTick: {
		show: false
	},
	axisLine: {
		show: false
	},
	z: 10
},
yAxis: {
	axisLine: {
		show: false
	},
	axisTick: {
		show: false
	},
	axisLabel: {
		textStyle: {
			color: '#fff'//柱状图纵坐标颜色
		}
	}
},
dataZoom: [{
	type: 'inside'
}],
  series: [
   {
  	type: 'bar',
  	itemStyle: {
  		normal: {
  			color: new echarts.graphic.LinearGradient(
  				0, 0, 0, 1, [{
  					offset: 0,
  					color: '#83bff6'
  				}, {
  					offset: 0.5,
  					color: '#188df0'
  				}, {
  					offset: 1,
  					color: '#188df0'
  				}]
  				)
  		},
  		emphasis: {
  			color: new echarts.graphic.LinearGradient(
  				0, 0, 0, 1, [{
  					offset: 0,
  					color: '#2378f7'
  				}, {
  					offset: 0.7,
  					color: '#2378f7'
  				}, {
  					offset: 1,
  					color: '#83bff6'
  				}]
  				)
  		}
  	},
  	data: datazhu,
  }],
  label: {
  	normal: {
  		show: true,
  		position: 'top',
  		formatter: '{c}'//formatter: '{c}次'可以在数据后面显示单位
  	}
  },
};
// Enable data zoom when user click bar.
var zoomSize = 6;//6就是点击一条左右最多各显示三条，比如如果点击最左边的就只显示右边三条
zhuZT.on('click', function(params) {
	console.log(dataAxis[Math.max(params.dataIndex - zoomSize / 2, 0)]);
	zhuZT.dispatchAction({
		type: 'dataZoom',
		startValue: dataAxis[Math.max(params.dataIndex - zoomSize / 2, 0)],
		endValue: dataAxis[Math.min(params.dataIndex + zoomSize / 2, datazhu.length - 1)]
	});
});
zhuZT.setOption(zhuoption);
	$.ajax({
	    url: url+'user/login',
	    type: 'post',
   		dataType: 'json',
   		async : false,//需要改成同步的
   		data:JSON.stringify({
   			'name':'qdkj-test',
   			'password':123456
   		}),
   		contentType: "application/json;charset=utf-8",
	async : false,//需要改成同步的
	}).done(function(data, status, jqXHR){
		$.ajax({
		    url: url+'system/deviceType?type=all',
		    type: 'get',
		    dataType: 'json',
		    async : false,//需要改成同步的
		    contentType: "application/json;charset=utf-8",
		    success:function(res){
		    	databing = JSON.stringify(res, null, 4);
		    	databing = JSON.parse(databing);
		    	// console.log(databing);
		    }
		})
	});

	for (var i = 0; i <databing.content.length; i++) {
		databing.content[i].value = Number(databing.content[i].value.substring(0,databing.content[i].value.length-1))
	}

	// var databiaoge = Mock.mock('biao.json','post',templatebiaoge);
	$.ajax({
	    url: url+'user/login',
	    type: 'post',
   		dataType: 'json',
   		async : false,//需要改成同步的
   		data:JSON.stringify({
   			'name':'qdkj-test',
   			'password':123456
   		}),
   		contentType: "application/json;charset=utf-8",
	async : false,//需要改成同步的
	}).done(function(data, status, jqXHR){
		$.ajax({
		    url: url+'system/deviceRealtimeOperation',
		    type: 'get',
	   		dataType: 'json',
	   		contentType: "application/json;charset=utf-8",
		async : false,//需要改成同步的
		}).done(function(data, status, jqXHR){
			var content = data.content;
			var status = 1;
			var len = content.length;
			var con = {};
			var htmlStr = "<table class='table'><thead><tr><th style='width:25%'>站点</th><th>站长</th><th>开启时间</th><th>状态</th></tr></thead><tbody>";
			for(var i = 0; i < len; i++){
			    con = content[i];
			    htmlStr += "<tr><td>"+con.stationName+"</td><td>"+con.masterName+"</td><td>"+con.createDate+"</td><td>"+con.status+"</td></tr>";
			}
			htmlStr += "</tbody></table>";
			$("#example").html(htmlStr);	
		});
	});

	var bingZT = echarts.init(document.getElementById('bingzt'));
	databing = [{
	    value:databing.content[0].value,
	    name: '智联保'
	}, {
	    value:databing.content[1].value,
	    name: '智能保'
	}];
	var bingoption = {
	    backgroundColor: 'rgba(255,255,255,0)',
	    tooltip: {
	        show: false,
	        trigger: 'item',
	        formatter: "{b}: {c} ({d}%)"
	    },
	    legend: {
	        orient: 'vertical',
	        left: '-5%',
	        data: ['智联保', '智能保'],
	        textStyle: {
	            color: '#fff',
	            fontWeight: 'bold',
	            fontSize: 15
	        }
	    },
	    series: [{
	        type: 'pie',
	        selectedMode: 'single',
	        radius: ['20%', '68%'],
	        color: ['#59ADF3', '#0A71A6', '#FF999A'],

	        label: {
	            normal: {
	                position: 'inner',
	                formatter: '{d}%',

	                textStyle: {
	                    color: '#fff',
	                    fontWeight: 'bold',
	                    fontSize: 20
	                }
	            }
	        },
	        labelLine: {
	            normal: {
	                show: false
	            }
	        },
	        data: databing
	    }]
	};

  	bingZT.setOption(bingoption);
  	window.addEventListener("resize",function(){
  		zhuZT.resize();
  		bingZT.resize();
  	});

